<?php

namespace app\admin\controller\user;

use app\common\controller\AdminController;
use EasyAdmin\annotation\ControllerAnnotation;
use EasyAdmin\annotation\NodeAnotation;
use think\App;
use think\facade\Db;

/**
 * @ControllerAnnotation(title="user_income")
 */
class Income extends AdminController
{

    use \app\admin\traits\Curd;

    public function __construct(App $app)
    {
        parent::__construct($app);

        $this->model = new \app\admin\model\UserIncome();
        
    }

    /**
     * @NodeAnotation(title="列表")
     */
    public function index()
    {
        if ($this->request->isAjax()) {
            if (input('selectFields')) {
                return $this->selectList();
            }
            list($page, $limit, $where) = $this->buildTableParames();

            $admin = session('admin');//
            $param = [];
            if(!empty($admin['uid'])){
                $param['b.bucket_id'] = $admin['uid'];
            }

            $count = $this->model
                ->alias('a')
                ->join("user b","a.id = b.id")
                ->where($param)
                ->where($where)
                ->count();
            $list = $this->model
                ->alias('a')
                ->join("user b","a.id = b.id")
                ->where($param)
                ->where($where)
                ->page($page, $limit)
                ->order($this->sort)
                ->field("a.*, b.nickname")
                ->select();
            $data = [
                'code'  => 0,
                'msg'   => '',
                'count' => $count,
                'data'  => $list,
            ];
            return json($data);
        }
        return $this->fetch();
    }

    public function viewinfo($id){
        $list = Db::name("user_income_record")
        ->alias('a')
        ->join("user b","a.fans_uid = b.id")
        ->where(['a.uid' =>$id])
        ->field("a.*,b.nickname as fansname")
        ->select();
        
        $this->assign("list", $list);
        return $this->fetch();
    }

    
}